package cn.lh.spider.controller;

import java.io.IOException;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import cn.lh.spider.dao.IData;
import cn.lh.spider.entity.Data;


@RequestMapping("/DatalistController")
@Controller
public class DatalistController {
	@Resource
	private IData data;
	@RequestMapping("/serachtype")
	@ResponseBody
	public void serachtype(HttpServletRequest req,Model model,HttpServletResponse resp,int page,int rows) throws IOException{
	
		
		resp.setCharacterEncoding("utf-8");
		resp.setContentType("application/json");
	//	req.setCharacterEncoding("UTF-8"); 
		String kaifa =req.getParameter("kaifa");
		String fenlei =req.getParameter("fenlei");
		String date =req.getParameter("date");
		String biaoti =req.getParameter("biaoti");
	
		int start = (page-1)*rows;
	    List<Data> data1 = data.findUsersListBytype(kaifa,fenlei,biaoti,date,start, rows);
		int count = data.countTaskBytype(kaifa,fenlei,biaoti,date);
	    String json = JSON.toJSONString(data1);
		String json1 = "{\"total\":"+count+",\"rows\":"+json+"}";
		
		
			resp.getWriter().print(json1);
	
		
		
	}

	@RequestMapping("/list")
	@ResponseBody
	public void list(HttpServletRequest req,Model model,HttpServletResponse resp,int page,int rows) throws Exception {

		try {
		
			resp.setCharacterEncoding("utf-8");
			resp.setContentType("application/json");
			int start = (page-1)*rows;
			int count = data.countTask();
			List<Data> datas= data.findUsersListByPage(start, rows);
			
			String json = JSON.toJSONString(datas);
			String json1 = "{\"total\":"+count+",\"rows\":"+json+"}";
			
			resp.getWriter().print(json1);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    
	}
}
